﻿// Author:					HoaPVT
// Created:					2010-10-18
// Last Modified:			2010-10-18
// 
// The use and distribution terms for this software are covered by the 
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)  
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by 
// the terms of this license.
//
// You must not remove this notice, or any other, from this software.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Globalization;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using mojoPortal.Web;
using ud_Links.Data;
using System.Linq;
using mojoPortal.Web.Framework;
using mojoPortal.Web.UI;
using Resources;
//using StandardMojoModule.Business;
//using Resources;

namespace ud_Links.UI
{

    public partial class LinksModule : SiteModuleControl
    {
        // FeatureGuid {A28436FD-0754-4729-A9E6-5327B0F39921}

        #region Declaration
        LinksConfiguration config = new LinksConfiguration();
        #endregion

        #region OnInit

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += Page_Load;
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
           //TODO: populate labels and controls
            LoadSettings();
            PopulateLabels();
            PopulateControls();            
        }

        private void PopulateControls()
        {
            TitleControl.EditUrl = SiteRoot + "/Links/Admin/AdminLinkEdit.aspx";
            TitleControl.Visible = !this.RenderInWebPartMode;
            if (this.ModuleConfiguration != null)
            {
                this.Title = this.ModuleConfiguration.ModuleTitle;
                this.Description = this.ModuleConfiguration.FeatureName;
            }
            ud_LinkDB linkDB = new ud_LinkDB(ModuleId);
            List<ud_Link> linkList = new List<ud_Link>();
            linkList = linkDB.GetAll();
            ddlX.DataSource = linkList;
            ddlX.DataTextField = "Name";
            ddlX.DataValueField = "Link";
            ddlX.DataBind();
            ddlX.Items.Insert(0, new ListItem(LinkModuleResource.InfoSelectLink, string.Empty));
            ddlX.SelectedIndex = 0;
        }


        private void PopulateLabels()
        {
            pnlContainer.ModuleId = ModuleId;
            TitleControl.EditText = LinkModuleResource.LinkEditPage;
        }

        private void LoadSettings()
        {
            config = new LinksConfiguration(Settings);
            pnlContainer.CssClass += " " + config.CustomCssClass;
        }



    }
}